'use strict';
	angular.module('accounting.accountYearSelectSingle', [])
	.controller('accountYearSelectSingleCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
			   , f])//控制器结束
    function f($rootScope, $scope, BizData, $uibModalInstance, params, title) {


		var Model = this;


		Model.gridRowClick = function(event){
			
		}

		Model.gridRowDblClick = function(event){
			Model.ok();
		}
		
		
		var options = {};
		options.container = Model;
		options.concept = 'FileCustomer';
		options.name = 'dataMaster';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.creater = '';
		options.reader = '/customer/customerInfo/selectSingle/query';
		options.writer = '';
		options.deleter = '';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.defCols = {fID:{name:"fID",type:"String",label:""},systemCode:{name:"systemCode",type:"String",label:""},billType:{name:"billType",type:"String",label:""},billTypeName:{name:"billTypeName",type:"String",label:""},orderDate:{name:"orderDate",type:"Date",label:""},state:{name:"state",type:"String",label:""},status:{name:"status",type:"String",label:""},storageTypeD:{name:"storageTypeD",type:"String",label:""},storageTypeDLabel:{name:"storageTypeDLabel",type:"String",label:""},customerNo:{name:"customerNo",type:"String",label:""},shortName:{name:"shortName",type:"String",label:""},customerName:{name:"customerName",type:"String",label:""},memberType:{name:"memberType",type:"String",label:""},memberTypeLabel:{name:"memberTypeLabel",type:"String",label:""},dealDateFirst:{name:"dealDateFirst",type:"Date",label:""},dealDateLast:{name:"dealDateLast",type:"Date",label:""},accountBank:{name:"accountBank",type:"String",label:""},accountNo:{name:"accountNo",type:"String",label:""},taxNo:{name:"taxNo",type:"String",label:""},invoiceCategory:{name:"invoiceCategory",type:"String",label:""},invoiceCategoryLabel:{name:"invoiceCategoryLabel",type:"String",label:""},settleCategory:{name:"settleCategory",type:"String",label:""},settleCategoryLabel:{name:"settleCategoryLabel",type:"String",label:""},taxType:{name:"taxType",type:"Integer",label:""},taxTypeLabel:{name:"taxTypeLabel",type:"String",label:""},taxRate:{name:"taxRate",type:"Decimal",label:""},depositRate:{name:"depositRate",type:"Decimal",label:""},sIDCard:{name:"sIDCard",type:"String",label:""},sPhone:{name:"sPhone",type:"String",label:""},sFax:{name:"sFax",type:"String",label:""},sAddressName:{name:"sAddressName",type:"String",label:""},sAddress:{name:"sAddress",type:"String",label:""},sAddressDetail:{name:"sAddressDetail",type:"String",label:""},sProvince:{name:"sProvince",type:"String",label:""},sCity:{name:"sCity",type:"String",label:""},sZone:{name:"sZone",type:"String",label:""},ognID:{name:"ognID",type:"String",label:""},sLoginName:{name:"sLoginName",type:"String",label:""},sMobilePhone:{name:"sMobilePhone",type:"String",label:""},sZip:{name:"sZip",type:"String",label:""},isMember:{name:"isMember",type:"Integer",label:""},memberNo:{name:"memberNo",type:"String",label:""},memberLevel:{name:"memberLevel",type:"String",label:""},memberLevelLabel:{name:"memberLevelLabel",type:"String",label:""},memberPoints:{name:"memberPoints",type:"Decimal",label:""},memberAmount:{name:"memberAmount",type:"Decimal",label:""},allocatedAmount:{name:"allocatedAmount",type:"Decimal",label:""},pendingAmount:{name:"pendingAmount",type:"Decimal",label:""},groupID:{name:"groupID",type:"String",label:""},employeeNo:{name:"employeeNo",type:"String",label:""},employeeName:{name:"employeeName",type:"String",label:""},comments:{name:"comments",type:"String",label:""},cUsercode:{name:"cUsercode",type:"String",label:""},cUsername:{name:"cUsername",type:"String",label:""},cDatetime:{name:"cDatetime",type:"Datetime",label:""},tUsercode:{name:"tUsercode",type:"String",label:""},tUsername:{name:"tUsername",type:"String",label:""},tDatetime:{name:"tDatetime",type:"Datetime",label:""},eUsercode:{name:"eUsercode",type:"String",label:""},eUsername:{name:"eUsername",type:"String",label:""},eDatetime:{name:"eDatetime",type:"Datetime",label:""},userId:{name:"userId",type:"String",label:""},enterpriseNo:{name:"enterpriseNo",type:"String",label:""},enterpriseName:{name:"enterpriseName",type:"String",label:""},version:{name:"version",type:"Integer",label:""}};
		options.isTree = false;
		options.parentRelation = 'fParent';
		options.nodeKindRelation = 'nodeKind';
		options.nodeLevelRelation = 'nodeLevel';
		options.pathRelation = 'fID';
		options.directDeleteMode = true;
		options.limit = 10;
		
		options.onIndexChanging = null;
		options.onIndexChanged = Model.dataMasterIndexChanged;
		options.onBeforeNew = Model.dataMasterBeforeNew;
		options.onAfterNew = Model.dataMasterAfterNew;
		options.onBeforeDelete = Model.dataMasterBeforeDelete;
		options.onAfterDelete = Model.dataMasterAfterDelete;
		options.onValueChanged = Model.dataMasterValueChanged;
		options.onDataChanged = Model.dataMasterDataChanged;
		
		$scope.dataMaster = new BizData(options);

		//监视对象中的所有变动
		$scope.dataMaster.deregRows = $scope.$watch('dataMaster.rows',$scope.dataMaster.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
		//////////////////////////////////////////////
		
		
		
		////////////////////启动执行开始///////////////////////////////////////////////////
		//接收调用的参数
//		Model.params = $rootScope.$stateParams;  
		


		////////////////////启动执行结束///////////////////////////////////////////////////
			

		
		
		//////////////////////对话框使用开始//////////////////////////////////////
		
        //模态窗口打开之后执行的事件
        $uibModalInstance.opened.then(function(){
    		//接收调用对话框的参数
            Model.title = title;  
            Model.params = params;  
    		//设置过滤条件
    		$scope.dataMaster.filter = "FileCustomer.status='open'";

    		//刷新数据
    	    $scope.dataMaster.refreshData();
        });  
		
        Model.ok = function () {  
	    	//保存成功
	    	//打包数据
	    	var event = {};
	    	var data = [];
	    	var sourceRow = $scope.dataMaster.rows[$scope.dataMaster.currentIndex];
	    	var row = {};
			//循环行中的列，判断变化点是哪一个
			for(var obj in sourceRow){
				if(obj!='$$hashKey' && obj!='userdata'){
					row[obj] = sourceRow[obj].value;
				}
			}
	    	
	    	data.push(row);
	    	event.data = data;
			$uibModalInstance.close(event);  
	    };  
	    
	    Model.cancel = function () {  
	        $uibModalInstance.dismiss('cancel');  
	    };    
		//////////////////////对话框使用结束//////////////////////////////////////
	    


		
		return Model;
	    
	    
	}	
	
